#ifndef APPLICATIONINFO_H
#define APPLICATIONINFO_H

#include "model/sourcemodel.h"
#include "model/articlemodel.h"
#include "model/categorymodel.h"
#include "model/contentmodel.h"

#include <QtCore/QObject>
#include <QtQml/QQmlPropertyMap>


class ApplicationInfo : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString dpi READ dpi NOTIFY dpiChanged)
    Q_PROPERTY(qreal ratio READ ratio NOTIFY ratioChanged)

    Q_PROPERTY(QObject *colors READ colors CONSTANT)
    Q_PROPERTY(QObject *constants READ constants CONSTANT)

    Q_PROPERTY(bool isHasUpdateMoreArticle READ isHasUpdateMoreArticle NOTIFY isHasUpdateMoreArticleChanged)
    Q_PROPERTY(bool isPortraitMode READ isPortraitMode WRITE setIsPortraitMode NOTIFY portraitModeChanged)
    Q_PROPERTY(int applicationWidth READ applicationWidth WRITE setApplicationWidth NOTIFY applicationWidthChanged)

    Q_PROPERTY(QString currentTitleArticle READ currentTitleArticle NOTIFY currentTitleArticleChanged)
    Q_PROPERTY(QString currenLinkSourceDomainArticle READ currenLinkSourceDomainArticle NOTIFY currenLinkSourceDomainArticleChanged)
    Q_PROPERTY(QString currentTimeArticle READ currentTimeArticle NOTIFY currentTimeArticleChanged)
    Q_PROPERTY(QString currentSourceInfoArticle READ currentSourceInfoArticle NOTIFY currentSourceInfoArticleChanged)
    Q_PROPERTY(bool updateContentSuccess READ updateContentSuccess NOTIFY updateContentSuccessChanged)


    Q_PROPERTY(SourceListModel *sourceInfos READ sourceInfos NOTIFY sourceListChanged)
    Q_PROPERTY(CategoryListModel *categoryListModel READ categoryListModel NOTIFY categorListChanged )


public:
    explicit ApplicationInfo(QObject *parent = 0);

    QQmlPropertyMap *colors() const { return m_colors; }
    QQmlPropertyMap *constants() const { return m_constants; }

    bool isPortraitMode() const { return m_isPortraitMode; }
    void setIsPortraitMode(const bool newMode);
    qreal ratio() const { return m_ratio; }
    bool isHasUpdateMoreArticle() const { return m_isHasUpdateMoreArticle; }
    QString dpi() const { return m_dpi; }

    QString currentTitleArticle() const { return m_currentTitleArticle; }
    QString currenLinkSourceDomainArticle() const { return m_currenLinkSourceDomainArticle; }
    QString currentTimeArticle() const { return m_currentTimeArticle; }
    QString currentSourceInfoArticle() const { return m_currentSourceInfoArticle; }

    bool updateContentSuccess() const { return m_updateContentSuccess; }

    int applicationWidth() const { return m_applicationWidth; }
    void setApplicationWidth(const int newWidth);
    SourceListModel* sourceInfos() const { return m_sourceInfos;}
    CategoryListModel* categoryListModel()const {return m_categoryListModel; }

signals:
    void isHasUpdateMoreArticleChanged();
    void portraitModeChanged();
    void ratioChanged();
    void applicationWidthChanged();
    void dpiChanged();
    void sourceListChanged();
    void categorListChanged();
    void addDataModelCategoryDelegate(QVariant dataListArticle,  QVariant idCategory);
    void displayContentArticle(QVariant title,
                               QVariant thumbnailImage,
                               QVariant time,
                               QVariant nameSourceArticle);

    void currentTitleArticleChanged();
    void currenLinkSourceDomainArticleChanged();
    void currentTimeArticleChanged();
    void currentSourceInfoArticleChanged();
    void updateContentSuccessChanged();
    void openingUpdateSuccess();

protected slots:

   void onAddListArticleByCategoryMoreChanged(CategoryDetail* aCategoryDetail, int cid);
   void onAddListArticleByCategoryNewChanged(CategoryDetail* aCategoryDetail, int cid);
   void onOpenContentArticleDetailRequest(const int categoryId, const int articleId);
   void onFinishGetSourceInfo();
   void onIsHasUpdateMoreArticle(bool check);
   void onHasDpiScreen(QString dpi);
   void onOpeningUpdateSuccess();

public slots:

    void initData();    
    void changeSource(const int sourceId );
    void notifyPortraitMode();

    ContentModel* getContentModel();

    ArticleListModel* getActicleListModel( int idCategory) ;
    void onAddListArticleByCategory(CategoryDetail* aCategoryDetail);

    void onSourceClick(int souceId);
    void onUpdateMoreCategoryRequest(int countCategoryCurrent);
    void onUpdateNewArticleRequest(int categoryId);
    void onUpdateMoreArticleRequest(int categoryId);
    void onUpdateContentArticleResponse(Article* article);

private:
    QQmlPropertyMap *m_colors;
    QQmlPropertyMap *m_constants;

    int m_applicationWidth;
    bool m_isPortraitMode;
    bool m_isMobile;
    qreal m_ratio;
    bool m_isHasUpdateMoreArticle;
    QString m_dpi;

    QString m_currentTitleArticle;
    QString m_currenLinkSourceDomainArticle;
    QString m_currentTimeArticle;
    QString m_currentSourceInfoArticle;

    bool m_updateContentSuccess;

    SourceListModel* m_sourceInfos;
    CategoryListModel* m_categoryListModel;
    QMap<int, ArticleListModel*> *m_mapCategoryId2Articles;
    ContentModel* m_contentModel;
    int m_currentSourceId;

};

#endif // APPLICATIONINFO_H
